<?php
function get_username($channel_name){
	switch($channel_name){
		case 'hecticsc':
			return 'HecticSC';
			break;
		case 'cheapcheese':
			return 'NOM|CheapCheese';
			break;
		case 'igaisrael':
			return 'IGA';
			break;
		case 'isneaks':
			return 'iSneak';
			break;
		case 'nomblight':
			return 'NOM|Blight';
			break;
		case 'hoolaboris':
			return 'NOM|plato';
			break;
		case 'sectorix':
			return 'NOM|Sectorix';
			break;
		case 'gulzarzilo':
			return 'NOM|Gulzar';
			break;
		case 'nomregba':
			return 'NOM|regba';
			break;
		case 'emans11':
			return 'PwR|eman';
			break;
		case 'freepwr':
			return 'PwR|free';
			break;
		case 'shadowmoopwr':
			return 'PwR|Shadowmoor';
			break;
		case 'jabotepwr':
			return 'PwR|Jabote';
			break;		
		case 'bh2412':
			return 'qTp|BHmaster';
			break;				
		case 'oz2973':
			return 'qTp|OzRe';
			break;	
		case 'fastrush':
			return 'Zokkar';
			break;
		case 'tubi2btubi':
			return 'Tubi';
			break;
		case 'alfonix':
			return 'Alfonix';
			break;
		case 'stinkycop':
			return 'StinkyCop';
			break;
		case 'ronlevi12012':
			return 'Sparox';
			break;
		default:
			return false;
			break;													
	}
}

//create array of channels
$channels = array(
			'HecticSC' => 'hecticsc',
			'NOM|CheapCheese' => 'cheapcheese',
			'IGA' => 'igaisrael',
			'iSneak' => 'isneaks',
			'NOM|Blight' => 'nomblight',
			'NOM|plato' => 'hoolaboris',
			'NOM|Sectorix' => 'sectorix',
			'NOM|Gulzar' => 'gulzarzilo',
			'NOM|regba' => 'nomregba',
			'PwR|eman' => 'emans11',
			'PwR|free' => 'freepwr',
			'PwR|Shadowmoor' => 'shadowmoopwr',
			'PwR|Jabote' => 'jabotepwr',
			'qTp|BHmaster' => 'bh2412',
			'qTp|OzRe' => 'oz2973',
			'Zokkar' => 'fastrush',
			'Tubi' => 'tubi2btubi',
			'Alfonix' => 'alfonix',
			'StinkyCop' => 'stinkycop',
			'Sparox' => 'ronlevi12012'
		);

$html = '';
$html .= <<<EOHTML
<div style="width:290px; border: solid 2px #0a7dcb; padding:5px; float:left; margin-left:6px; text-align:left; direction:ltr; height:100%;">
<div style="text-align:right;">
שידורים חיים של ישראלים
</div>
<hr>
EOHTML;


$jsonurl = "http://api.justin.tv/api/stream/list.json?channel=hecticsc,cheapcheese,igaisrael,isneaks,nomblight,hoolaboris,sectorix,gulzarzilo,nomregba,emans11,freepwr,shadowmoopwr,jabotepwr,bh2412,oz2973,fastrush,tubi2btubi,alfonix,stinkycop,ronlevi12012";
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json);

foreach($json_output as $stream){
	$viewers = $stream->channel_count;
	$channel_name = $stream->channel->login;
	
	$html .= "<span style='font-weight:bold; color:green;'>Online(".$viewers.")</span> <a href='http://www.twitch.tv/$channel_name' target='_blank'>" . get_username($channel_name) . '</a><hr style="margin: 0px 0;"/>';
	unset($channels[get_username($channel_name)]);
}	

foreach ($channels as $channName => $channel) {
	$html .= '<span style="font-weight:bold; color:red;">Offline</span> <a href="http://www.twitch.tv/'.$channel.'" target="_blank">' . $channName . '</a><hr style="margin: 0px 0;"/>'; 
}

$html .= <<<EOHTML
<br />
<a href="http://israelstreams.x10.mx/">
Much thanks to the lovely Sectorix!
</a>
</div>
EOHTML;

echo $html;